const devConfig = require('./webpack.dev.config')
const webpack = require('webpack')
const opn = require('opn')
const path = require('path')
const express = require('express')

const app = express()
const compiler = webpack(devConfig)


app.use(require('webpack-dev-middleware')(compiler, {
    publicPath: devConfig.output.publicPath
}))

app.use(require('webpack-hot-middleware')(compiler, {
    log: false
}))

// 同时也提供直接访问static文件夹的途径
// 注意以下的路径基于express运行时的文件夹<根文件夹> 而不是目前所在文件夹 所以用'./'而非'../'
app.use('/static', express.static('./static'))

app.listen(3000, () => {
    console.log('Example app listening on port 3000!\n')
    opn('http://localhost:3000')
})